package com.example.back.controller;

import com.example.back.dto.req.DeleteCheckupDto;
import com.example.back.dto.req.PutawayCheckupDto;
import com.example.back.dto.resp.CheckupProductList;
import com.example.back.service.CheckupProductService;
import com.example.common.entity.CheckupProduct;
import com.example.common.support.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName CheckupProductController
 * @Author wengjt
 * @Date 2021/5/8 13:28
 * @Description
 **/
@RestController
@RequestMapping("/checkupProduct")
@Api(tags = "体检套餐管理")
public class CheckupProductController {
    @Resource
    private CheckupProductService checkupProductService;

    @GetMapping("/list")
    @ApiOperation(value = "获取体检套餐列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "cpName", value = "套餐名字"),
            @ApiImplicitParam(name = "ctId", value = "套餐类型id"),
            @ApiImplicitParam(name = "showAble", value = "是否上下架"),
            @ApiImplicitParam(name = "pageNum", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小"),
    })
    public Result<CheckupProductList> getCheckupProductList(String cpName,
                                                            Long ctId,
                                                            Integer showAble,
                                                            Integer pageNum,
                                                            Integer pageSize) {
        return Result.success(checkupProductService.getCheckupProductList(cpName, ctId, showAble, pageNum, pageSize));
    }

    @GetMapping("")
    @ApiOperation(value = "获取单个体检套餐详情")
    @ApiImplicitParam(name = "cpId", value = "套餐id")
    public Result<CheckupProduct> getInfo(Long cpId) {
        return Result.success(checkupProductService.getInfo(cpId));
    }

    @PutMapping("")
    @ApiOperation(value = "修改体检套餐详细")
    public Result<Object> updateCheckupProduct(@RequestBody CheckupProduct checkupProduct) {
        return Result.success(checkupProductService.UpdateCheckupProduct(checkupProduct));
    }

    @PostMapping("")
    @ApiOperation(value = "新增体检套餐")
    public Result<Object> insertCheckupProduct(@RequestBody CheckupProduct checkupProduct) {
        return Result.success(checkupProductService.insertCheckProduct(checkupProduct));
    }

    @PostMapping("/putaway")
    @ApiOperation(value = "上下架体检套餐")
    public Result<Object> putawayCheckupProduct(@RequestBody PutawayCheckupDto dto) {
        return Result.success(checkupProductService.putawayCheckupProduct(dto.getCpId(), dto.getShowAble()));
    }

    @DeleteMapping("")
    @ApiOperation(value = "删除体检套餐")
    public Result<Object> deleteCheckupProduct(@RequestBody DeleteCheckupDto dto) {
        return Result.success(checkupProductService.deleteCheckupProduct(dto.getCpId()));
    }
}
